local zhufa = fk.CreateSkill {
  name = "rmt__zhufa",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["rmt__zhufa"] = "主法",
  [":rmt__zhufa"] = "锁定技，除【法】以外的伤害牌进入弃牌堆后，你将之移出游戏。若同名牌均移出，将五张【法】洗入牌堆。",

  ["$rmt__zhufa1"] = "你还没有见过真正的恐惧。",
  ["$rmt__zhufa2"] = "这些，你就感到害怕了吗？"
}

zhufa:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(zhufa.name) then
      local room = player.room
      local cards = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            local card = Fk:getCardById(info.cardId, true)
            if card.name ~= "charm" and card.is_damage_card and table.contains(room.discard_pile, info.cardId) then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
      cards = room.logic:moveCardsHoldingAreaCheck(cards)
      if #cards > 0 then
        event:setCostData(self, {cards = cards})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = event:getCostData(self).cards
    room:moveCardTo(ids, Card.Void, nil, fk.ReasonJustMove, self.name, nil, true, player)
    if Fk.all_card_types["charm"] == nil then return end
    for _, id in ipairs(ids) do
      if not table.find(Fk.cards, function (card)
        return card.trueName == Fk:getCardById(id).trueName and
        room:getCardArea(card.id) ~= Card.Void and room:getCardArea(card.id) ~= Card.Unknown
      end) then
        local moves = {}
        for _ = 1, 5, 1 do
          local c = room:printCard("charm", math.random(4), math.random(13))
          table.insert(moves, {
            ids = {c.id},
            toArea = Card.DrawPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
            proposer = player,
            moveVisible = true,
            drawPilePosition = math.random(#room.draw_pile),
          })
        end
        room:moveCards(table.unpack(moves))
      end
    end
  end,
})

return zhufa
